#!/bin/lua
local io = require("io")
local json = require("json")
local curl = require("cURL")

function download(filename, directory, url)
    local f = io.open(directory..filename, "wb")
    c = curl.easy_init()
    c:setopt_url(url)
    c:perform({
        writefunction = function(str)
            f:write(str)
        end
    })
    f:close()
end

local plugins_file = io.open("plugins/plugins.json", "rb")
local plugins_json = json.decode(plugins_file:read("a"))

plugins_file:close()

for num,plugin in ipairs(plugins_json["plugins"]) do
    download(plugin["name"], "plugins/", plugin["url"])
end

for num,plugin in ipairs(plugins_json["colors"]) do
    -- download(plugin["name"], "colors/", plugin["url"])
end
